package com.example.mainstream.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.shopapp.R;

/**
 * 文件名：PayTypesDialog
 * 描述：支付方式Dialog
 */
public class PayTypesDialog extends Dialog {

    ImageView mIvWeiChatPay;
    ImageView mIvZhiFuBaoPay;
    TextView tv_zhifubao,tv_weixin;
    Button btn_confirm;

    private OnPayLinstener linstener;
    //dialog构造方法 实现时需要传上下文和一个dialog主题
    public PayTypesDialog(@NonNull Context context, int themeResId, OnPayLinstener linstener) {
        super(context, themeResId);
        this.linstener = linstener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_pay);
        mIvZhiFuBaoPay = findViewById(R.id.iv_pay_type_zhifubao);
        mIvWeiChatPay = findViewById(R.id.iv_pay_type_weixin);
        tv_weixin = findViewById(R.id.tv_weixin);
        tv_zhifubao = findViewById(R.id.tv_zhifubao);
        btn_confirm = findViewById(R.id.btn_confirm);
        //设置基本属性
        Window dialogWindow = getWindow();
        //设置在底部显示
        dialogWindow.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        //设置宽度和手机持平
        lp.width = AbsListView.LayoutParams.MATCH_PARENT;
        lp.y = 0;//设置Dialog距离底部的距离
        dialogWindow.setAttributes(lp);


        mIvWeiChatPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIvWeiChatPay.setSelected(true);
                mIvZhiFuBaoPay.setSelected(false);
            }
        });
        tv_weixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIvWeiChatPay.setSelected(true);
                mIvZhiFuBaoPay.setSelected(false);
            }
        });
        mIvZhiFuBaoPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIvZhiFuBaoPay.setSelected(true);
                mIvWeiChatPay.setSelected(false);
            }
        });
        tv_zhifubao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mIvZhiFuBaoPay.setSelected(true);
                mIvWeiChatPay.setSelected(false);
            }
        });
        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //选择提现方式
                if (mIvZhiFuBaoPay.isSelected()) {
                    if(linstener != null){
                        linstener.onPayClick(1);
                        dismiss();
                    }
                } else if (mIvWeiChatPay.isSelected()) {
                    if(linstener != null){
                        linstener.onPayClick(2);
                        dismiss();
                    }
                }
            }
        });

    }


}

